FROM eclipse-temurin:21-jdk AS builder

RUN apt update && apt install unzip -y

WORKDIR /opt

RUN wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/mvnd/2.0.0-rc-3/maven-mvnd-2.0.0-rc-3-linux-amd64.zip \
&& unzip maven-mvnd-2.0.0-rc-3-linux-amd64.zip

ENV PATH=$PATH:/opt/maven-mvnd-2.0.0-rc-3-linux-amd64/bin

COPY . /app

WORKDIR /app

RUN mvnd dependency:resolve

RUN mvnd package

FROM eclipse-temurin:21-jre-alpine AS runner

# 换源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories

# 安装 ffmpeg
RUN apk update && apk add ffmpeg

FROM runner
# 设置工作目录
WORKDIR /app

# 复制依赖
COPY --from=builder /app/target/lib /app/lib

# 复制本体
COPY --from=builder /app/target/*.jar /app

ENTRYPOINT ["java"]

CMD ["-jar", "x-stick-downloader-1.0.0.jar"]